{layout name="public/layout" /}
<!-- 内容主体区域 -->
<div class="site-block">
    <blockquote class="layui-elem-quote">
            <span class="layui-breadcrumb" lay-separator=">">
                <a href="">首页</a>
                <a><cite>设置配置</cite></a>
            </span>
    </blockquote>
    <fieldset class="layui-elem-field">
        <div class="layui-field-box">
            <form class="layui-form layui-form-pane" method="post">
                <div class="layui-form-item layoui-l ">
                    <div class="layui-inline" >
                        <label class="layui-form-label ">发货数量</label>
                        <div class="layui-input-inline" {:InputStyle('80')}>
                            <input type="text" name="number" lay-verify="required|number" autocomplete="off" class="layui-input" value="1">
                        </div>
                    </div>
                <div class="layui-inline" >
                    <label class="layui-form-label ">卡密元素</label>
                    <div class="layui-input-inline" {:InputStyle('100')}>
                        <input type="text" name="kaminums" autocomplete="off" class="layui-input" placeholder="!@#$%^符号" value="">
                    </div>
                </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">卡密类别</label>
                        <div class="layui-input-block" {:InputStyle('100')}>
                            <select name="km_type" lay-filter="aihao">
                                <option value="" ></option>
                                {volist name="dlarr" id="vo"}
                                <option value="{$vo.id}">{$vo.d_name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">代理会员</label>
                        <div class="layui-input-inline">
                            <input type="text" name="km_uid"  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="formDemo">生成卡密</button>
                    </div>
                </div>
            </form>

            <hr class="layui-bg-orange">
                <style>
                    table thead tr th{text-align: center}
                </style>
            <table class="layui-table" lay-even lay-skin="" >

                <thead>
                <tr>
                    <th>
                        <input type="checkbox" lay-skin="primary">
                    </th>
                    <th>代理会员</th>
                    <th>代理类别</th>
                    <th>卡密号码</th>
                    <th>卡密类型</th>
                    <th>状态</th>
                    <th>生成时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>

                {volist name="kmarr" id="vo"}
                <tr id="km_id_{$vo.km_id}">
                    <td>{$vo.km_id}</td>
                    <td>{$vo.km_uid|user_name}</td>
                    <td>{$vo.km_uid}</td>
                    <td>{$vo.km_number}</td>
                    <td>{$vo.km_type|type_name}</td>
                    <td>{$vo.km_sell?"已使用":'未使用'}</td>
                    <td>{$vo.km_time|date('Y-m-d H:i',=###)}</td>
                    <td>
                        <div class="layui-btn-group">
                            <button class="layui-btn layui-btn-sm layui-btn-danger" onclick="delcfm('{$vo.km_id}');"><i class="layui-icon"></i> 删除</button>
                        </div>
                    </td>
                </tr>
                {/volist}
                </tbody>

            </table>
            {$kmarr->render()}
        </div>
    </fieldset>
</div>

<script>
    //Demo
    layui.use('element', function(){
        var element = layui.element;

        //…
    });
    function delcfm(id){
        layer.confirm('确定要删除该卡密吗？', {
            btn: ['确认','取消'] //按钮
        }, function(){
            $.ajax({
                url:'{:url("Kami/Del_km")}',
                type:'post',
                data:{km_id:id},
                dataType:"json"
            }).done(function(res) {
                if(res.code==0){
                    layer.msg(res.msg,function(){});
                }else{
                    layer.msg(res.msg,{time:500},function(){
                        $('#km_id_'+id).hide();
                    });
                }
            })
            .fail(function() {
                layer.msg('系统异常，请稍后再试',function(){})
            });
        });
    }

    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data){
            $.ajax({
                url: "{:url('Kami/kami')}",
                type: "post",
                data: data.field,
                dataType: "json"
            }).done(function(res) {
                if(res.code==0){
                    layer.msg(res.msg,function(){});
                }else{
                    layer.alert(res.msg,function(){
                        window.location.href=res.url;
                    });
                }
            })
            .fail(function() {
                layer.msg('系统异常，请稍后再试',function(){})
            });
            return false;
        });
    });
</script>